using UnityEngine;
using UnityEngine.UI;

public class DisplayGamePoints : GenericDialog
{
	public Image[] points;

	public Image slider;

	public Image sliderBg;

	private float[] timesForLevel;

	private int currentPoints = 5;

	private float pointStartTime;

	private void OnEnable()
	{
		Reset();
	}

	private void LateUpdate()
	{
		if (currentPoints != 0)
		{
			float levelTime = Game.levelTime;
			float num = timesForLevel[currentPoints - 1];
			if (num - pointStartTime == 0f)
			{
				slider.fillAmount = 1f;
			}
			else
			{
				slider.fillAmount = Mathf.Clamp(1f - (levelTime - pointStartTime) / (num - pointStartTime), 0f, 1f);
			}
			if (levelTime > num)
			{
				points[currentPoints - 1].CrossFadeColor(new Color(0.118f, 0.118f, 0.118f, 1f), 0.1f, true, false);
				currentPoints--;
				pointStartTime = num;
			}
		}
	}

	public void Reset()
	{
		currentPoints = 5;
		pointStartTime = 0f;
		if (Game.currentLevelNumber > 0)
		{
			timesForLevel = Economy.GetPointTimesForLevel(Game.currentLevelNumber);
		}
		else
		{
			timesForLevel = new float[5];
		}
		for (int i = 0; i < points.Length; i++)
		{
			points[i].CrossFadeColor(Color.white, 0f, true, false);
		}
		slider.fillAmount = 1f;
	}

	public override void Show()
	{
		base.Show();
		slider.gameObject.SetActive(true);
		sliderBg.gameObject.SetActive(true);
	}

	public override void Hide()
	{
		base.Hide();
		slider.gameObject.SetActive(false);
		sliderBg.gameObject.SetActive(false);
	}
}
